<?php

declare(strict_types = 1);

namespace App\Exception\Handler;

use App\Core\Response;
use Hyperf\Di\Annotation\Inject;
use Psr\Http\Message\ResponseInterface;
use Hyperf\ExceptionHandler\ExceptionHandler;
use Phper666\JwtAuth\Exception\TokenValidException;
use Throwable;

class AppTokenValidExceptionHandler extends ExceptionHandler {
    /**
     * @Inject
     * @var Response
     */
    protected $response;

    public function handle(Throwable $throwable, ResponseInterface $response) {
        $this->stopPropagation();
        return $this->response->error($throwable->getCode(),$throwable->getMessage());
    }

    public function isValid(Throwable $throwable): bool {
        return $throwable instanceof TokenValidException;
    }

}